/**
 * 判断是否是电话
 * @param str
 * @returns {boolean}
 */
function isPhone(str) {
  let re = /^1\d{10}$/;
  if (re.test(str)) {
    return true
  } else {
    return false
  }
}

/**
 * 判断是否是邮箱
 * @param str
 * @returns {boolean}
 */
function isEmail(str) {
  let re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
  if (re.test(str)) {
    return true
  } else {
    return false
  }
}

/**
 * 生成随机字符串大小写敏感
 * @param len
 * @returns {string}
 */
function randomString(len) {
  len = len || 32;
  var $chars = 'abcdefghzklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  var maxPos = $chars.length;
  var pwd = '';
  for (let i = 0; i < len; i++) {
    pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return pwd;
}

module.exports = {
  isPhone,isEmail,randomString
}
